﻿<Window x:Class="Onvif_IP_Camera_Manager.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:controls="clr-namespace:Ozeki.Media.Video.Controls;assembly=VoIPSDK"
        xmlns:viewer="clr-namespace:Onvif_IP_Camera_Manager.View"
        xmlns:converter="clr-namespace:Onvif_IP_Camera_Manager.View.Converters"
        xmlns:log="clr-namespace:Onvif_IP_Camera_Manager.LOG"
        Icon="/Onvif IP Camera Manager;component/Resources/ip_camera_sdk_icon_transparent_128x128.png"
        DataContext="{Binding RelativeSource={RelativeSource Self}}"
        WindowStartupLocation="CenterScreen"
        Title="Ozeki IP Camera Manager Demo" Height="650" Width="1000" Closing="MainWindow_OnClosing" Loaded="MainWindow_OnLoaded" ResizeMode="CanMinimize">

    <Window.Resources>
        <converter:BoolInverterConverter x:Key="BoolInverterConverter" />
        <converter:DevicesToListConverter x:Key="DevicesToListConverter" />
        <converter:CameraClientConverter x:Key="CameraClientConverter"/>
        <converter:VisibilityConverter x:Key="VisibilityConverter"/>
        <Style x:Key="{x:Type Slider}" TargetType="Slider">
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Width" Value="220"/>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40"></RowDefinition>
            <RowDefinition Height="1*"></RowDefinition>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="6*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="1*"/>
            </Grid.ColumnDefinitions>
            <Label Content="Onvif IP Camera Manager" HorizontalAlignment="Left" HorizontalContentAlignment="Left" VerticalAlignment="Center" FontSize="18" FontWeight="Bold" Height="34" Width="311" Margin="0,3" />
            <Button Grid.Column="1" Content="About Ozeki" Height="23" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="RoyalBlue" Background="White" Click="btnAboutOzeki_Click" />
            <Button Grid.Column="2" Content="Projects" Height="23" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Click="btnProjects_Click" />
            <Button Grid.Column="3" Content="Website" Height="23" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Click="btnWebsite_Click" />
            <Button Grid.Column="4" Content="Purchase" Height="23" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Click="btnPurchase_Click" />
            <Button Grid.Column="5" Content="Help" Height="23" VerticalAlignment="Center" Click="btnHelp_Click" HorizontalAlignment="Center" Width="75" />
        </Grid>

        <TabControl Grid.Row="1">
            <TabItem Header="Device manager">
                <Grid Background="#FFE5E5E5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="45*"/>
                        <ColumnDefinition Width="55*"/>
                    </Grid.ColumnDefinitions>
                    <Grid Grid.Column="0">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="160"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="30"/>
                        </Grid.RowDefinitions>
                        <GroupBox Grid.Row="0" Header="Camera connection" >
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="70"/>
                                    <ColumnDefinition Width="235"/>
                                    <ColumnDefinition Width="156*"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30"/>
                                    <RowDefinition Height="35"/>
                                    <RowDefinition Height="35"/>
                                    <RowDefinition Height="30"/>
                                </Grid.RowDefinitions>
                                <Label Grid.Column="0" Content="Cameras:" Width="58" />
                                <ComboBox Name="CameraDevicesCombo" Width="230" ItemsSource="{Binding ConnectModel.DeviceList,Converter={StaticResource DevicesToListConverter}}" SelectedItem="{Binding ConnectModel.SelectedDevice, Mode=TwoWay}"
                                Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Height="25" HorizontalAlignment="Left" VerticalAlignment="Center" VerticalContentAlignment="Bottom" SelectionChanged="CameraDevicesCombo_SelectionChanged" />

                                <Button Grid.Row="0" Content="Refresh" Grid.Column="2" Width="55" HorizontalAlignment="Left" Margin="5,2,5,3" Click="Refresh_Click" ToolTip="Refreshes the list of discoverable network cameras and USB cameras."/>
                                <Button Grid.Row="0" Content="Add" Grid.Column="2" Width="55" HorizontalAlignment="Right" Margin="5,2,5,3" Click="AddButton_Click" ToolTip="Adds manually a camera with the set Address, UserName and Password."/>

                                <!--Camera Address-->
                                <!--<Label Grid.Row="2" Grid.Column="0" Content="Address:"/>
                                <TextBox Text="{Binding CameraAddress, Mode=TwoWay, NotifyOnSourceUpdated=True}" Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" TextAlignment="Left" HorizontalAlignment="Left" Width="340" Margin="0,5,5,5"/>-->

                                <!--Username-->
                                <Label Grid.Row="1" Grid.Column="0" Content="UserName:"/>
                                <TextBox Text="{Binding UserName, Mode=TwoWay}" Grid.Row="1" Grid.Column="1" TextAlignment="Left" HorizontalAlignment="Stretch" Margin="0,5,5,5"/>
                                <Label Content="(optional)" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" Margin="2,0,0,0"/>

                                <!--Password-->
                                <Label Grid.Row="2" Grid.Column="0" Content="Password:"/>
                                <TextBox Text="{Binding Password, Mode=TwoWay}" Grid.Row="2" Grid.Column="1" TextAlignment="Left" HorizontalAlignment="Stretch" Margin="0,5,5,5"/>
                                <Label Content="(optional)" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Left" Margin="2,0,0,0"/>

                                <!--<Button Content="Remove camera" Grid.Row="4" Grid.Column="2" Margin="0,4,5,2" Width="90" HorizontalAlignment="Right" Click="RemoveButton_Click" ToolTip="Removes the selected camera from the list."/>-->

                                <Button Grid.Row="3" Grid.Column="1" Content="Connect" Height="26" Width="90" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="ConnectButton_Click" Margin="0" ToolTip="Connects to the selected camera."/>
                                <Button Grid.Row="3" Grid.Column="1" Content="Disconnect" Height="26" Width="90" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="DisconnectButton_Click" Margin ="0,0,5,0" ToolTip="Disconnects from the selected camera."/>

                            </Grid>
                        </GroupBox>
                        <GroupBox  Grid.Row="1" Header="Live camera  -  draw edges to resize the viewer">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <GridSplitter Grid.Row="1" HorizontalAlignment="Right" 
                VerticalAlignment="Stretch" 
                Grid.Column="0"
                Width="5" Background="#FFBCBCBC"/>

                                <GridSplitter Grid.Row="1" HorizontalAlignment="Left" 
                VerticalAlignment="Stretch" 
                Grid.Column="2"
                Width="5" Background="#FFBCBCBC"/>

                                <Grid Grid.Row="1" Name="CameraBox" Grid.Column="1" >
                                    <controls:VideoViewerWPF Name="videoViewer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black"/>
                                </Grid>

                                <GridSplitter Grid.Row="0"  VerticalAlignment="Bottom" 
                HorizontalAlignment="Stretch" 
                Grid.Column="1" 
                Height="5"  Background="#FFBCBCBC"/>

                                <GridSplitter Grid.Row="2"  VerticalAlignment="Top" 
                HorizontalAlignment="Stretch" 
                Grid.Column="1" 
                Height="5"  Background="#FFBCBCBC"/>
                            </Grid>
                        </GroupBox>

                        <Border Grid.Row="2" Margin="0,4,0,2" BorderBrush="DarkGray" BorderThickness="0">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Label HorizontalAlignment="Left" Content="State:" Margin="10,0,0,0"/>
                                <Border Grid.Column="0" BorderBrush="DarkGray" BorderThickness="1" Margin="50,0,5,0">
                                    <TextBlock Margin="5,3,2,1" Text="{Binding CurrentModel.CameraState}"/>
                                </Border>

                                <Label HorizontalAlignment="Left" Content="Error:" Grid.Column="1" Margin="10,0,0,0"/>
                                <Border Grid.Column="1" BorderBrush="DarkGray" BorderThickness="1" Margin="50,0,10,0">
                                    <TextBlock Margin="5,3,2,1" Text="{Binding CurrentModel.CameraError}"/>
                                </Border>
                            </Grid>
                        </Border>
                    </Grid>


                    <TabControl Grid.Column="1" Margin="5,0,-5,0">
                        <TabItem Header="Stream">
                            <Grid Background="#FFE5E5E5" >
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="2*"/>
                                    <RowDefinition Height="1*"/>
                                </Grid.RowDefinitions>

                                <Grid Grid.Row="0">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="30"/>
                                        <RowDefinition Height="1*"/>
                                    </Grid.RowDefinitions>
                                    <Grid Grid.Row="0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="112*"/>
                                            <ColumnDefinition Width="411*"/>
                                        </Grid.ColumnDefinitions>
                                        <Label Grid.Column="0" Content="Available streams:" Width="105" Margin="0,5,5,0" />
                                        <ComboBox IsEnabled="{Binding IsIPCamera}" Grid.Column="1" Name="StreamComboBox" VerticalContentAlignment="Center" ItemsSource="{Binding CurrentModel.CameraStreams}" SelectedItem="{Binding CurrentModel.CurrentStream}" SelectionChanged="StreamComboBox_SelectionChanged" Margin="5,5,5,0" />
                                    </Grid>

                                    <Grid Margin="0,0,0,0" Grid.Row="1">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="1*"/>
                                            <ColumnDefinition Width="1*"/>
                                        </Grid.ColumnDefinitions>
                                        <GroupBox Header="Audio" Grid.Column="0" IsEnabled="{Binding IsIPCamera}">
                                            <TextBox Name="DeviceAudioInfo" Text="{Binding CurrentModel.AudioStreamInfo}" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsReadOnly="True" />
                                        </GroupBox>
                                        <GroupBox Header="Video" Grid.Column="1" IsEnabled="{Binding IsIPCamera}">
                                            <TextBox Name="DeviceVideoInfo" Text="{Binding CurrentModel.VideoStreamInfo}" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsReadOnly="true"/>
                                        </GroupBox>
                                    </Grid>
                                </Grid>

                                <GroupBox Header="Device Information" Grid.Row="1">
                                    <TextBox IsReadOnly="True" Text="{Binding CurrentModel.DeviceInfo, Mode=TwoWay}" TextWrapping="WrapWithOverflow" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"/>
                                </GroupBox>

                            </Grid>
                        </TabItem>
                        <TabItem Header="Image settings">
                            <Grid Background="#FFE5E5E5" IsEnabled="{Binding IsIPCamera}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="1*"/>
                                    <RowDefinition Height="9*"/>
                                </Grid.RowDefinitions>
                                <Grid Grid.Row="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="1*"/>
                                        <ColumnDefinition Width="2*"/>
                                    </Grid.ColumnDefinitions>

                                    <GroupBox Header="Flip">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="1*"/>
                                                <ColumnDefinition Width="1*"/>
                                            </Grid.ColumnDefinitions>
                                            <CheckBox Name="HorizontalCheckBox" Content="Horizontal" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="FlipCheck" Unchecked="FlipCheck"/>
                                            <CheckBox Name="VerticalCheckBox" Content="Vertical" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Checked="FlipCheck" Unchecked="FlipCheck" />
                                        </Grid>
                                    </GroupBox>
                                    <GroupBox Grid.Column="1" Header="Control size">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="1*"/>
                                                <ColumnDefinition Width="1*"/>
                                                <ColumnDefinition Width="1*"/>

                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Content="Height" Grid.Column="0"/>
                                                <TextBox Height="25" Name="HeightTextBox" Grid.Column="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                                            </Grid>
                                            <Grid Grid.Column="1">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Content="Width" Grid.Column="0"/>
                                                <TextBox Height="25" Name="WidthTextBox" Grid.Column="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                                            </Grid>

                                            <Button Height="25" Width="70" Content="Apply" Grid.Column="2" Click="ApplySizeButton_Click"/>
                                        </Grid>
                                    </GroupBox>
                                </Grid>

                                <Grid Grid.Row="1" IsEnabled="{Binding IsImagingSupported}" >
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                        <RowDefinition Height="1*"/>
                                    </Grid.RowDefinitions>

                                    <viewer:ImageSetting Grid.Row="0" x:Name="BrightnessSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="Brightness"/>
                                    <viewer:ImageSetting Grid.Row="1" x:Name="ContrastSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="Contrast"/>
                                    <viewer:ImageSetting Grid.Row="2" x:Name="SaturationSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="Saturation"/>
                                    <viewer:ImageSetting Grid.Row="3" x:Name="SharpnessSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="Sharpness"/>
                                    <viewer:ImageSetting Grid.Row="4" x:Name="BackLightSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="BackLight"/>
                                    <viewer:ImageSetting Grid.Row="5" x:Name="WhiteBalanceCbSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="WhiteBalanceCb"/>
                                    <viewer:ImageSetting Grid.Row="6" x:Name="WhiteBalanceCrSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="WhiteBalanceCr"/>
                                    <viewer:ImageSetting Grid.Row="7" x:Name="FrameRateSlider" Model="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=CurrentModel}" SettingName="FrameRate"/>
                                </Grid>
                            </Grid>
                        </TabItem>
                        <TabItem Header="PTZ">
                            <Grid Background="#FFE5E5E5" IsEnabled="{Binding IsIPCamera}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="1*"/>
                                    <RowDefinition Height="1*"/>
                                    <RowDefinition Height="1*"/>
                                </Grid.RowDefinitions>

                                <Grid Grid.Row="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="3*"/>
                                        <ColumnDefinition Width="1*"/>
                                        <ColumnDefinition Width="3*"/>
                                    </Grid.ColumnDefinitions>


                                    <GroupBox Grid.Column="0" Header="Control">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="1*"/>
                                                <RowDefinition Height="1*"/>
                                                <RowDefinition Height="1*"/>
                                            </Grid.RowDefinitions>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="1*"/>
                                                <ColumnDefinition Width="1*"/>
                                                <ColumnDefinition Width="1*"/>
                                            </Grid.ColumnDefinitions>

                                            <Button Grid.Row="0" Grid.Column="0" Content="Up Left" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                            <Button Grid.Row="0" Grid.Column="1" Content="Up" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                            <Button Grid.Row="0" Grid.Column="2" Content="Up Right" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>

                                            <Button Grid.Row="1" Grid.Column="0" Content="Left" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                            <Button Grid.Row="1" Grid.Column="1" Content="Home" Margin="5" FontSize="10" Name="HomeButton" Click="HomeButton_OnClick" />
                                            <Button Grid.Row="1" Grid.Column="2" Content="Right" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>

                                            <Button Grid.Row="2" Grid.Column="0" Content="Down Left" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                            <Button Grid.Row="2" Grid.Column="1" Content="Down" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                            <Button Grid.Row="2" Grid.Column="2" Content="Down Right" Margin="5" FontSize="10" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>

                                        </Grid>
                                    </GroupBox>

                                    <GroupBox Header="Zoom" Grid.Column="1">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <Button Grid.Row="0" Height="30" Width="40" Content="In" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                            <Button Grid.Row="1" Height="30" Width="40" Content="Out" PreviewMouseLeftButtonDown="ControlMovement" PreviewMouseLeftButtonUp="ControlStop"/>
                                        </Grid>
                                    </GroupBox>

                                    <GroupBox Header="Preset" Grid.Column="2">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="1*"/>
                                                <RowDefinition Height="1*"/>
                                                <RowDefinition Height="1*"/>
                                            </Grid.RowDefinitions>
                                            <Grid Grid.Row="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Button Grid.Column="0" Width="70" Height="30" Content="Set home" Name="SetHomeButton" Click="SetHomeButton_Click"/>
                                                <Button Grid.Column="1" Width="70" Height="30" Content="Add preset" Name="AddPresetButton" Click="AddPresetButton_Click" Margin="0,0,-10,0"/>
                                            </Grid>

                                            <Label Content="Presets:" Grid.Row="1" HorizontalAlignment="Left" Margin="16, 0, 0, 0"/>
                                            <ComboBox Grid.Row="1" Margin="12,0,14,0" Name="PresetsComboBox" Width="130" Height="25" ItemsSource="{Binding CurrentModel.CameraPresets}" HorizontalAlignment="Right" />
                                            <Grid Grid.Row="2">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Button Grid.Column="0" Width="70" Height="30" Content="Move" Name="MoveToPresetButton" Click="MoveToPresetButton_Click"/>
                                                <Button Grid.Column="1" Width="70" Height="30" Content="Delete" Name="DeletePresetButton" Click="DeletePresetButton_Click" Margin="0,0,-10,0"/>
                                            </Grid>
                                        </Grid>
                                    </GroupBox>

                                </Grid>

                                <GroupBox Margin="0, 20, 0, 20" Header="Scanner" Grid.Row="1">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid Grid.Row="0" Grid.Column="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="2*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Direction:"/>
                                            <ComboBox Name="DirectionComboBox" Grid.Column="1" Height="25" />
                                        </Grid>
                                        <Grid Grid.Row="0" Grid.Column="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="1*"/>
                                                    <ColumnDefinition Width="1*"/>
                                                </Grid.ColumnDefinitions>
                                                <Button Name="ScanStartButton" Grid.Column="0" HorizontalAlignment="Right" Width="40" Height="30" Content="Scan" Click="ScanStartButton_Click"/>
                                                <Button Name="ScanStopButton" Grid.Column="1" Width="40" Height="30" Content="Stop" Click="ScanStopButton_Click"/>
                                            </Grid>

                                        </Grid>
                                        <Grid Grid.Row="1" Grid.Column="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Duration:"/>
                                            <TextBox Name="DurationTextBox" Grid.Column="1" Height="25"/>
                                            <Label Grid.Column="2" Content="second" Margin="0,0,30,0"/>
                                        </Grid>
                                    </Grid>
                                </GroupBox>

                                <GroupBox Header="Speed" Grid.Row="2">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                        <Grid Grid.Row="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="2*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Pan:"/>
                                            <Slider Grid.Column="1" Name="PanSlider" Value="1" Minimum="1" Maximum="100" ValueChanged="SpeedPropertyChange"/>
                                            <Label HorizontalAlignment="Left" Grid.Column="2" ContentStringFormat="{}{0:N0}" Content="{Binding Value, ElementName=PanSlider}"/>
                                        </Grid>
                                        <Grid Grid.Row="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="2*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Tilt:"/>
                                            <Slider Grid.Column="1" Value="1" Name="TiltSlider" Minimum="1" Maximum="100"/>
                                            <Label HorizontalAlignment="Left" Grid.Column="2" ContentStringFormat="{}{0:N0}" Content="{Binding Value, ElementName=TiltSlider}"/>
                                        </Grid>
                                        <Grid Grid.Row="2">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="2*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Zoom:"/>
                                            <Slider Grid.Column="1" Value="1" Name="ZoomSlider" Minimum="1" Maximum="100"/>
                                            <Label HorizontalAlignment="Left" Grid.Column="2" ContentStringFormat="{}{0:N0}" Content="{Binding Value, ElementName=ZoomSlider}"/>
                                        </Grid>
                                    </Grid>
                                </GroupBox>

                            </Grid>
                        </TabItem>
                        <TabItem Header="Alarms and capture">
                            <Grid Background="#FFE5E5E5">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0.3*"/>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="0.4*"/>

                                </Grid.RowDefinitions>
                                <GroupBox Header="Capture" Grid.Row="0">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                        <Grid Grid.Row="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="129*"/>
                                                <ColumnDefinition Width="100"/>
                                                <ColumnDefinition Width="100"/>
                                                <ColumnDefinition Width="100"/>
                                            </Grid.ColumnDefinitions>
                                            <Button Grid.Column="1" Content="Take snapshot" Width="90" Name="CaptureImageButton" Click="CaptureImageButton_Click" HorizontalAlignment="Right" Margin="0,4"/>
                                            <Button Grid.Column="2" Content="Start Video" Width="90" Name="StartCaptureVideoButton" Click="StartCaptureVideoButton_Click" HorizontalAlignment="Right" Margin="0,4"/>
                                            <Button Grid.Column="3" Content="Stop Video" Width="90" Name="StopCaptureVideoButton" Click="StopCaptureVideoButton_Click" HorizontalAlignment="Right" Margin="0,4"/>
                                        </Grid>
                                        <Grid Grid.Row="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="75"/>
                                                <ColumnDefinition Width="348*"/>
                                                <ColumnDefinition Width="100"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Directory:" />
                                            <Button Grid.Column="2" Content="Browse" Name="FilePathButton" HorizontalAlignment="Right" Width="90" Click="FilePathButton_Click" Margin="0,4"/>
                                            <TextBox Grid.Column="1" Margin="0,5" Text="{Binding CapturePath}" />
                                        </Grid>
                                    </Grid>
                                </GroupBox>

                                <GroupBox Header="Motion Detection" Grid.Row="1">
                                    <Grid Margin="5">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="0.1*"/>
                                            <RowDefinition Height="0.2*"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="0.2*"/>
                                            <RowDefinition Height="0.2*"/>
                                        </Grid.RowDefinitions>
                                        <Grid Grid.Row="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <CheckBox VerticalAlignment="Center" Grid.Column="0" Margin="7,0,0,0" Content="Enable motion detection" Checked="Enable_Motion_Detection" Unchecked="Enable_Motion_Detection"/>
                                            <CheckBox VerticalAlignment="Center" Grid.Column="1" Content="Enable sound detection" Checked="Enable_Sound_Detection" Unchecked="Enable_Sound_Detection" />
                                        </Grid>
                                        <Grid Grid.Row="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="1*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Content="Recording Duration (seconds):" Margin="1,0,0,0"/>
                                            <TextBox Text="{Binding CurrentModel.Duration}" Grid.Column="1" HorizontalAlignment="Left" Height="25" Width="50" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
                                        </Grid>
                                        <GroupBox Header="Motion Log" Grid.Row="2">
                                            <ListBox ItemsSource="{Binding Source={x:Static log:Log.MotionLogList}}">

                                            </ListBox>
                                        </GroupBox>
                                        <Grid Grid.Row="3">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="100"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="100"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Pixel intensity:"/>
                                            <Slider Grid.Column="1" Maximum="255" Name="PixelIntensitySlider" ValueChanged="MotionPropertyValueChanged" />
                                            <Label Grid.Column="2" HorizontalAlignment="Left" ContentStringFormat="{}{0:N0}" Content="{Binding Value, ElementName=PixelIntensitySlider}" />
                                        </Grid>
                                        <Grid Grid.Row="4">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="100"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="100"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Content="Pixel amount:"/>
                                            <Slider Grid.Column="1" Minimum="0" Maximum="100" Name="PixelAmountSlider" ValueChanged="MotionPropertyValueChanged" />
                                            <Label Grid.Column="2" HorizontalAlignment="Left" ContentStringFormat="{}{0:#.00}%" Content="{Binding Value, ElementName=PixelAmountSlider}"  />
                                        </Grid>
                                    </Grid>
                                </GroupBox>

                                <Grid Grid.Row="2">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <GroupBox Header="FTP" Grid.Row="0">
                                        <Grid>

                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="2*"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <CheckBox Grid.Column="0" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Center" Content="Upload captured file to FTP" Name="UploadCapturedFileFtpCheckBox"/>
                                            <Button Grid.Column="1" Height="25" Width="70" Content="Setting" Click="FtpSettingButton_Click" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                        </Grid>
                                    </GroupBox>

                                    <GroupBox Header="Email" Grid.Row="1">
                                        <Grid>

                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="2*"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <CheckBox Grid.Column="0" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Content="Send captured file in email" Name="SendCapturedFileEmailCheckBox"/>

                                            <Button Grid.Column="1" Height="25" Width="70" Content="Setting" Name="EmailSettingButton" Click="EmailSettingButton_Click" HorizontalAlignment="Center" VerticalAlignment="Center"/>

                                        </Grid>
                                    </GroupBox>
                                </Grid>
                            </Grid>
                        </TabItem>

                        <TabItem Header="SIP call">
                            <Grid Background="#FFE5E5E5">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="320"/>
                                    <RowDefinition Height="221*"/>
                                </Grid.RowDefinitions>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="270"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <GroupBox Grid.Row="0" Header="SIP account settings" Grid.Column="0" VerticalAlignment="Stretch">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="35"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>

                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="100"/>
                                            <ColumnDefinition Width="2*"/>
                                        </Grid.ColumnDefinitions>

                                        <Label Grid.Row="0" Grid.Column="0" Content="Display name:" Margin="0,5,0,0"/>
                                        <TextBox Height="25" VerticalContentAlignment="Center" Grid.Row="0" Grid.Column="1" Text="{Binding AccountModel.DisplayName}" Margin="0,5,0,0"/>
                                        <Label Grid.Row="1" Grid.Column="0" Content="User name:"/>
                                        <TextBox Height="25" VerticalContentAlignment="Center" Grid.Row="1" Grid.Column="1" Text="{Binding AccountModel.UserName}"/>
                                        <Label Grid.Row="2" Grid.Column="0" Content="Auth name:"/>
                                        <TextBox Height="25" VerticalContentAlignment="Center" Grid.Row="2" Grid.Column="1" Text="{Binding AccountModel.RegisterName}"/>
                                        <Label Grid.Row="3" Grid.Column="0" Content="Password:"/>
                                        <TextBox Height="25" VerticalContentAlignment="Center" Grid.Row="3" Grid.Column="1" Text="{Binding AccountModel.Password}"/>
                                        <Label Grid.Row="4" Grid.Column="0" Content="Domain:"/>
                                        <TextBox Height="25" VerticalContentAlignment="Center" Grid.Row="4" Grid.Column="1" Text="{Binding AccountModel.Domain}"/>
                                        <Label Grid.Row="5" Grid.Column="0" Content="Outbound Proxy:"/>
                                        <TextBox Height="25" VerticalContentAlignment="Center" Grid.Row="5" Grid.Column="1" Text="{Binding AccountModel.OutboundProxy}"/>
                                        <CheckBox Grid.Row="6" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Content="Registration required" IsChecked="{Binding AccountModel.RegistrationRequired}"/>
                                        <Button Content="Register" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Left" Click="SipRegistrationButton_Click" Width="60" Height="25" />
                                        <Button Content="Unregister" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Left" Click="SipUnregistrationButton_Click" Width="60" Height="25" Margin="65,0,0,0" />
                                        <Label Grid.Row="8" Grid.Column="0" Content="Phone line state:"/>
                                        <TextBox Grid.Row="8" Grid.Column="1" Text="{Binding SoftPhone.PhoneLine.RegistrationInfo.State}" IsReadOnly="True" VerticalContentAlignment="Center" />
                                    </Grid>

                                </GroupBox>

                                <GroupBox Height="197" Header="Alarm call" Grid.ColumnSpan="2" Grid.Row="1">
                                    <Grid >
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="100"/>
                                            <ColumnDefinition Width="165*"/>
                                            <ColumnDefinition Width="103*"/>
                                            <ColumnDefinition Width="121*"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="100"/>
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="30"/>
                                        </Grid.RowDefinitions>
                                        <CheckBox VerticalAlignment="Center" Grid.Column="1" Grid.ColumnSpan="3" Content="Call the following phone numbers when motion detected" Name="AlarmCallCheckBox"/>

                                        <Label Grid.Column="0" Grid.Row="1" Content="Add number:" VerticalAlignment="Top" />
                                        <TextBox HorizontalContentAlignment="Left" Grid.Row="1"  VerticalAlignment="Center" Name="DialNumberTextBox" Height="25" Text="{Binding DialAdd}" Grid.Column="1" />
                                        <Button Margin="10,0,0,0"  Name="AddButton" Height="25" Width="60" Grid.Column="2" Grid.Row="1" Content="Add" HorizontalAlignment="Left" Click="AddNumber_Click" />

                                        <Label Grid.Column="0" Grid.Row="2" Content="Numbers to dial:" VerticalAlignment="Top" />
                                        <ListBox Grid.Column="1" Grid.Row="2" Height="95" ItemsSource="{Binding SoftPhone.AlarmList}" VerticalAlignment="Top" />
                                        <Button Name="RemoveButton" Margin="10,0,0,0" Height="25" Width="60" Grid.Column="2" Grid.Row="2" VerticalAlignment="Top" Content="Remove" HorizontalAlignment="Left" Click="RemoveNumber_Click" />
                                    </Grid>
                                </GroupBox>
                                <GroupBox Grid.Column="1" Header="Phone call">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="60"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="40"/>
                                            <RowDefinition Height="158*"/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="95"/>
                                            <ColumnDefinition Width="114*"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="Enter the phone number where the stream of the web or IP camera will be forwarded." TextWrapping="Wrap" Grid.ColumnSpan="2" Margin="10,10,10,22" Grid.RowSpan="2" />
                                        <Label Grid.Column="0" Content="Number to dial:" Grid.Row="1" />
                                        <TextBox Grid.Column="1" Grid.Row="1" Height="25" Text="{Binding SoftPhone.SelectedDial}"/>
                                        <Label Grid.Column="0" Content="Call state:" Grid.Row="3" />
                                        <TextBox Grid.Column="1" Grid.Row="3" Height="25" IsReadOnly="True" Text="{Binding SoftPhone.CurrentCallState}"/>
                                        <Button Grid.Column="1" Content="Call" Click="CallButton_Click" Margin="0,2" Grid.Row="2" Height="25" HorizontalAlignment="Left" Width="47"/>
                                        <Button Content="Hang up" Click="CallHangUpButton_Click" Margin="52,2,0,2" Grid.Column="1" Grid.Row="2" Height="25" HorizontalAlignment="Left" Width="66"/>
                                    </Grid>
                                </GroupBox>
                            </Grid>
                        </TabItem>

                        <TabItem Header="Camera settings">
                            <Grid Background="#FFE5E5E5" IsEnabled="{Binding IsIPCamera}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="0.8*"/>
                                    <RowDefinition Height="0.7*"/>
                                    <RowDefinition Height="1*"/>
                                </Grid.RowDefinitions>
                                <Grid Grid.Row="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="1*"/>
                                        <ColumnDefinition Width="1*"/>
                                    </Grid.ColumnDefinitions>
                                    <GroupBox Grid.Row="0" Header="Time settings" Grid.Column="0" Margin="0,0,1,0">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="0.8*"/>
                                                <RowDefinition Height="0.5*"/>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="Auto"/>

                                            </Grid.RowDefinitions>
                                            <Grid Grid.Row="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="60"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="Zone:"/>
                                                <ComboBox Grid.Column="1" Height="30" ItemsSource="{Binding GetTimeZones}" SelectedItem="{Binding CurrentTimeZone}"/>
                                            </Grid>
                                            <Grid Grid.Row="1">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>

                                                <RadioButton Content="Use UTC" GroupName="TimeGroup" IsChecked="{Binding UseUTC}"  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="25,0,0,0" Grid.Column="0"/>

                                                <RadioButton Content="Set UTC manually" GroupName="TimeGroup" IsChecked="{Binding UseUTC, Converter={StaticResource BoolInverterConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Column="1"/>
                                            </Grid>
                                            <Grid Grid.Row="2">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="*"/>
                                                </Grid.RowDefinitions>
                                                <Grid Grid.Row="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="105"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="Date"/>
                                                    <DatePicker Grid.Column="1" SelectedDate="{Binding SelectedDate}" SelectedDateFormat="Long" Name="DatePickerSetting" />
                                                </Grid>
                                                <Grid Grid.Row="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="105"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="Time (HH:MM:SS)"/>
                                                    <TextBox Grid.Column="1" Text="{Binding SelectedTime}"/>
                                                </Grid>
                                            </Grid>
                                            <Button Grid.Row="3" Height="25" Width="60" HorizontalAlignment="Right" Content="Set" Click="SetTimeSettingsButton_Click" />
                                        </Grid>
                                    </GroupBox>

                                    <GroupBox Grid.Column="1" Header="Property" Margin="1,0,0,0">
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <Grid Grid.Row="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="75"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="Name:"/>
                                                <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.CameraName}"/>
                                            </Grid>
                                            <Grid Grid.Row="1">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="75"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="Location:"/>
                                                <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.CameraLocation}"/>
                                            </Grid>
                                            <CheckBox Content="Discoverable" Grid.Row="2" Margin="75,0,0,0" Name="DiscoverAbleCheckbox" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                                            <Button Content="Set" Grid.Row="3" HorizontalAlignment="Right" Width="60" Name="SetPropertyButton" Click="SetPropertyButton_Click" Margin="0,8,0,0"/>
                                        </Grid>
                                    </GroupBox>
                                </Grid>

                                <GroupBox Header="User management" Grid.Row="1">
                                    <Grid>
                                        <Grid.Resources>
                                            <Style x:Key="{x:Type Button}" TargetType="Button">
                                                <Setter Property="Margin" Value="15,0,0,0"/>
                                            </Style>
                                        </Grid.Resources>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="*"/>
                                        </Grid.RowDefinitions>
                                        <Grid Grid.Row="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="80"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="80"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>

                                            <Label Grid.Column="0" Content="Users"/>
                                            <ComboBox Grid.Column="1" Height="25" ItemsSource="{Binding CurrentModel.GetCameraUsers}" SelectedItem="{Binding CameraUser}" Name="UserListComboBox" SelectionChanged="UserListComboBox_SelectionChanged" />
                                            <Label Grid.Column="2" Content="Role:" Margin="0,0,5,0"/>
                                            <ComboBox Grid.Column="3" Height="25" ItemsSource="{Binding GetCameraUsersLevel}" SelectedItem="{Binding Role}" Margin="5,0,0,0"/>
                                        </Grid>
                                        <Grid Grid.Row="1">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="Username"/>
                                                <TextBox Grid.Column="1" Height="25"  Text="{Binding CameraUser.UserName}" />
                                            </Grid>
                                        </Grid>
                                        <Grid Grid.Row="2">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="Password"/>
                                                <TextBox Grid.Column="1" Height="25" Text="{Binding CameraUser.Password}"/>
                                            </Grid>
                                        </Grid>
                                        <Grid Grid.Row="3">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid Grid.Column="0">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="80"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Label Grid.Column="0" Content="Repeat Pass"/>
                                                <TextBox Grid.Column="1" Height="25" Text="{Binding Password2}" />
                                            </Grid>
                                            <Grid Grid.Column="1" Margin="5,0,0,0" HorizontalAlignment="Right">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Button Grid.Column="0" Content="Add" Height="25" Width="60" Click="AddUserButton_Click"/>
                                                <Button Grid.Column="1" Content="Modify" Height="25" Width="60" Click="ModifyUserButton_Click"/>
                                                <Button Grid.Column="2" Content="Delete" Height="25" Width="60" Click="DeleteUserButton_Click"/>
                                            </Grid>
                                        </Grid>
                                    </Grid>
                                </GroupBox>

                                <GroupBox Grid.Row="2" Header="Network settings">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="2*"/>
                                            <RowDefinition Height="10*"/>
                                        </Grid.RowDefinitions>

                                        <Grid Grid.Row="0" Margin="0,0,0,0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <RadioButton Content="DHCP" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding CurrentModel.Network.DefaultConfig.UseDHCP, Converter={StaticResource BoolInverterConverter}}"/>
                                            <RadioButton x:Name="IsDHCP" Content="Manual network setting" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding CurrentModel.Network.DefaultConfig.UseDHCP}" />
                                        </Grid>
                                        <!--<GroupBox Grid.Column="0" Grid.Row="1" Header="Setting" IsEnabled="{Binding IsChecked, ElementName=IsDHCP}">-->
                                        <StackPanel Grid.Column="0" Grid.Row="1" IsEnabled="{Binding IsChecked, ElementName=IsDHCP}">
                                            <Grid >
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="*"/>
                                                </Grid.RowDefinitions>

                                                <Grid Grid.Row="0" Grid.Column="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="IP"/>
                                                    <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.Network.DefaultConfig.IPAddress}" />
                                                </Grid>
                                                <Grid Grid.Row="1" Grid.Column="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="Netmask"/>
                                                    <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.Network.DefaultConfig.Netmask}"/>
                                                </Grid>
                                                <Grid Grid.Row="2" Grid.Column="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="Gateway"/>
                                                    <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.Network.DefaultConfig.DefaultGateway}"/>
                                                </Grid>
                                                <Grid Grid.Row="3" Grid.Column="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="DNS"/>
                                                    <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.Network.DefaultConfig.DNS}"/>
                                                </Grid>
                                                <Grid Grid.Row="4" Grid.Column="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="Host"/>
                                                    <TextBox Grid.Column="1" Height="25" Text="{Binding CurrentModel.Network.DefaultConfig.HostName}"/>
                                                </Grid>
                                                <Grid Grid.Row="0" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="NTP"/>
                                                    <Label Grid.Column="1" Height="25" Content="{Binding CurrentModel.Network.DefaultConfig.NTP.IPAddress}" />
                                                </Grid>
                                                <Grid Grid.Row="1" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="HTTP"/>
                                                    <ComboBox Grid.Column="1" Height="25" ItemsSource="{Binding CurrentModel.Network.HttpPort.Port}"/>
                                                </Grid>
                                                <Grid Grid.Row="2" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="HTTPS"/>
                                                    <ComboBox Grid.Column="1" Height="25" ItemsSource="{Binding CurrentModel.Network.HttpsPort.Port}"/>
                                                </Grid>
                                                <Grid Grid.Row="3" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="RTSP"/>
                                                    <ComboBox Grid.Column="1" Height="25" ItemsSource="{Binding CurrentModel.Network.RtspPort.Port}"/>
                                                </Grid>

                                                <Grid Grid.Row="4" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="60"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                </Grid>

                                            </Grid>
                                        </StackPanel>
                                        <!--</GroupBox>-->
                                        <Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="25" Width="70" Content="Save" Click="SaveNetworkButton_Click"/>
                                    </Grid>
                                </GroupBox>
                            </Grid>
                        </TabItem>

                        <TabItem Header="Server">
                            <Grid Background="#FFE5E5E5">
                                <GroupBox Header="Camera server" Background="#FFE5E5E5" >
                                    <Grid>

                                        <TextBlock FontWeight="Bold" FontSize="16" TextWrapping="Wrap" Text="You have to connect to a camera first, to be able to start a server."  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,-200,0,0"/>
                                    </Grid>
                                </GroupBox>
                                
                                <GroupBox Header="Camera server" Background="#FFE5E5E5" Visibility="{Binding CurrentModel.CameraState, Converter={StaticResource VisibilityConverter}, Mode=OneWay}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="100"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>

                                        <GroupBox Header="Set Listen Address" Grid.Row="0" Margin="0,0,0,0">
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="40"/>
                                                </Grid.RowDefinitions>
                                                <Grid Grid.Row="0">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="130"/>
                                                        <ColumnDefinition Width="220"/>
                                                        <ColumnDefinition Width="3*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="VideoLAN - VLC URL:"/>
                                                    <TextBox Grid.Column="1" Height="25" Text="{Binding Server.CameraUrl, Mode=OneWay}" Margin="0,0,10,0" Grid.ColumnSpan="2" IsReadOnly="True"/>
                                                    <!--<Label Grid.Column="2" Content="Port:" HorizontalAlignment="Left"/>
                                                    <TextBox Grid.Column="2" HorizontalAlignment="Right" Width="110" Height="25" Text="{Binding Server.Port}" Margin="0,0,10,0"/>-->
                                                </Grid>

                                                <Grid Grid.Row="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="130"/>
                                                        <ColumnDefinition Width="220"/>
                                                        <ColumnDefinition Width="3*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Label Grid.Column="0" Content="State:" HorizontalAlignment="Right"/>
                                                    <Border Grid.Column="1" HorizontalAlignment="Left" Width="150" Margin="0,10,0,6" BorderBrush="DarkGray" BorderThickness="1">
                                                        <TextBlock Margin="2,3,2,1" FontWeight="Bold" Text="{Binding Server.State}" TextAlignment="Center"/>
                                                    </Border>
                                                    <Button Grid.Column="2" Click="StartButton" Content="Start" Height="25" Width="70" Margin="0,0,0,0" HorizontalAlignment="Left"/>
                                                    <Button Grid.Column="2" Click="StopButton" Content="Stop" Height="25" Width="70" Margin="0,0,10,0" HorizontalAlignment="Right"/>
                                                </Grid>
                                            </Grid>
                                        </GroupBox>

                                        <GroupBox Header="Connected clients" Grid.Row="3">
                                            <ListBox ItemsSource="{Binding Server.ConnectedClients, Converter={StaticResource CameraClientConverter}}" />
                                        </GroupBox>

                                    </Grid>
                                </GroupBox>
                            </Grid>
                        </TabItem>
                        <TabItem Header="Web">
                            <Grid Background="#FFE5E5E5">
                                <GroupBox Header="Camera server" Background="#FFE5E5E5" >
                                    <Grid>

                                        <TextBlock FontWeight="Bold" FontSize="16" TextWrapping="Wrap" Text="You have to connect to a camera first, to be able to start a server."  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,-200,0,0"/>
                                    </Grid>
                                </GroupBox>
                                <GroupBox Header="Camera server" Background="#FFE5E5E5" Visibility="{Binding CurrentModel.CameraState, Converter={StaticResource VisibilityConverter}}">
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="100"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="*"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>

                                        <Button Click="btnWebstream_Click" Content="Open site" Height="25" Width="153" Margin="10,10,0,65" HorizontalAlignment="Left"/>
                                        <Label HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Content="Number of connected clients" Margin="10,35,0,35"/>

                                        <GroupBox Grid.Row="0" Header="Connected clients" Margin="0,76,0,24" Grid.RowSpan="4">
                                            <ListBox ItemsSource="{Binding Server.ConnectedClients, Converter={StaticResource CameraClientConverter}}" />
                                        </GroupBox>

                                    </Grid>
                                </GroupBox>
                            </Grid>
                        </TabItem>
                    </TabControl>

                </Grid>
            </TabItem>
            <TabItem Header="Camera viewer">
                <Grid Background="#FFE5E5E5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <viewer:CameraViewerControl Grid.Row="0" Grid.Column="0" x:Name="Viewer1" ModelList="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=ModelList}"/>
                    <viewer:CameraViewerControl Grid.Row="0" Grid.Column="1" x:Name="Viewer2" ModelList="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=ModelList}"/>
                    <viewer:CameraViewerControl Grid.Row="1" Grid.Column="0" x:Name="Viewer3" ModelList="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=ModelList}"/>
                    <viewer:CameraViewerControl Grid.Row="1" Grid.Column="1" x:Name="Viewer4" ModelList="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewer:MainWindow}}, Path=ModelList}"/>
                </Grid>
            </TabItem>

            <TabItem Header="Log">
                <ListBox ItemsSource="{Binding Source={x:Static log:Log.LogList}}" >

                </ListBox>
            </TabItem>
        </TabControl>


    </Grid>
</Window>
